﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Ricciolo.Controls;
using System.Windows.Controls;
using System.Windows.Data;
using OpenExpressApp.Editors;

namespace OpenExpressApp.Module.WPF.Editors.TreeColumn
{
    /// <summary>
    /// 下拉列
    /// </summary>
    public class LookupListTreeColumn : TreeColumn
    {
        private LookupListPropertyEditor _editor;

        public LookupListTreeColumn(BusinessObjectPropertyInfo info, IListObjectView view)
            : base(info, view)
        {
            this._editor = new LookupListPropertyEditor(this.PropertyInfo, this.View);
        }

        public override IWPFPropertyEditor Editor
        {
            get
            {
                return this._editor;
            }
        }

        protected override FrameworkElementFactory GenerateElementFactoryInBorder()
        {
            FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));
            var title = ApplicationModel.GetBusinessObjectInfo(PropertyInfo.LookupAttribute.LookupType).TitleInfo.Name;
            Binding b = new Binding(PropertyInfo.LookupAttribute.LookupPropertyName + "." + title);
            textBlock.SetBinding(TextBlock.TextProperty, b);
            return textBlock;
        }
        protected override FrameworkElement GenerateElementInBorder()
        {
            TextBlock tb = new TextBlock();
            Binding TextBinding = new Binding(PropertyInfo.LookupAttribute.LookupPropertyName + "." + ApplicationModel.GetBusinessObjectInfo(PropertyInfo.LookupAttribute.LookupType).TitleInfo.Name);
            tb.SetBinding(TextBlock.TextProperty, TextBinding);
            return tb;
        }
    }
}
